package com.xiaolei.lib.Activity.bean;

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;

import com.xiaolei.lib.annotation.factory.BeanFactory;

/**
 * 一个，或者多个注解进行的一个包裹
 * 
 * @author xiaolei
 */
public class AnnotationWrape extends LinkedList<Class<? extends Annotation>>
{
	private static final long serialVersionUID = -1700033365241573761L;
	private Map<Class<? extends Annotation>, Annotation> annotationStore = null;

	public AnnotationWrape()
	{
		// TODO Auto-generated constructor stub
	}

	public AnnotationWrape(Class<? extends Annotation>... classes)
	{
		for (Class<? extends Annotation> class1 : classes)
		{
			this.add(class1);
		}
		Collections.sort(this, BeanFactory.getInstance(ComparatorExt.class));
	}

	public void put(Class<? extends Annotation> annotation, Annotation value)
	{
		if (annotationStore == null)
		{
			synchronized (AnnotationWrape.class)
			{
				annotationStore = new HashMap<Class<? extends Annotation>, Annotation>();
			}
		}
		annotationStore.put(annotation, value);
	}
	
	@SuppressWarnings("unchecked")
	public <T extends Annotation> T get(Class<T> annotation)
	{
		return (T) annotationStore.get(annotation);
	}
}
